package org.example;

import cn.clj1.MyClojureInterp;
import cn.clj1.CljCharIterator;
import cn.clj1.CljLexer;
import cn.clj1.CljLinesFromString;
import cn.clj1.MyClojureReader;
import cn.clj1.cell.CljCell;
import org.junit.Test;

import java.util.Hashtable;

public class MyClojure_reader_case {

    public static MyClojureReader getReader(String txt)
    {
        CljLinesFromString myIInput = new CljLinesFromString(txt);
        CljCharIterator myCharIterator = new CljCharIterator(myIInput);
        CljLexer lexer = new CljLexer(myCharIterator);
        MyClojureReader myLispReader = new MyClojureReader(lexer);
        return myLispReader;
    }

    @Test
    public void test_1() throws Exception {
        MyClojureReader myLispReader = getReader("{:a 12 :b \"吴大富\"}");
        CljCell myCell = myLispReader.getExpression();
        System.out.println(myCell.toString());
    }

    @Test
    public void test_2() throws Exception {
        MyClojureReader myLispReader = getReader("{:a 12 :b \"吴大富\"}");
        CljCell myCell = myLispReader.getExpression();
        CljCell myCell1 = MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        System.out.println(myCell1.toString());
    }

    @Test
    public void test_12() throws Exception {
        MyClojureReader myLispReader = getReader("(def n 0)");
        CljCell myCell = myLispReader.getExpression();
        System.out.println(myCell.toString());
    }

    @Test
    public void test_22() throws Exception {
        MyClojureReader myLispReader = getReader("(do (def n 10) (println n))");
        CljCell myCell = myLispReader.getExpression();
        //MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        CljCell myCell1 = MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        System.out.println(myCell1);
    }

    @Test
    public void test_112() throws Exception {
        MyClojureReader myLispReader = getReader("((fn [a b] (+ a b)) (+ 1 2 3) 2)");
        CljCell myCell = myLispReader.getExpression();
        //System.out.println(myCell.toString());
        CljCell myCell1 = MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        System.out.println(myCell1);
    }

    @Test
    public void test_152() throws Exception {
        MyClojureReader myLispReader = getReader("(#(+ %1 %2) 1.5 2)");
        CljCell myCell = myLispReader.getExpression();
        System.out.println(myCell.toString());
        CljCell myCell1 = MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        System.out.println(myCell1);
    }

    @Test
    public void test_153() throws Exception {
        MyClojureReader myLispReader = getReader("(#(println %) \"吴大富是一个大帅哥！\")");
        CljCell myCell = myLispReader.getExpression();
        //System.out.println(myCell.toString());
        CljCell myCell1 = MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        System.out.println(myCell1);
    }
}




































